package com.wjj.happytime.activity.me_activity;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.test.mock.MockApplication;
import com.jiongbull.jlog.JLog;
import com.wjj.happytime.R;
import com.wjj.happytime.adapter.happy_frg_adapter.ItemAdapter;
import com.wjj.happytime.application.BaseApplication;
import com.wjj.happytime.entity.happy_entity.PerItem;
import com.wjj.happytime.entity.happy_entity.User;
import java.util.LinkedList;

public class MyCollectActivity extends AppCompatActivity {

  public RecyclerView rvCollect;
  public SQLiteDatabase db;
  public LinkedList<PerItem> datas;
  public ItemAdapter adapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_collect);
    rvCollect = ((RecyclerView) findViewById(R.id.rv_collect));
    //数据源
    db = ((BaseApplication) getApplication()).db;
    Cursor cursor = db.rawQuery("SELECT * FROM tableListen", null);
//    format,thumb,name,content,low_loc,high_loc,low_url,pic_url
    datas = new LinkedList<>();
    while(cursor.moveToNext()) {
      JLog.e("cursor.moveToNext()");
      String format = cursor.getString(cursor.getColumnIndex("format"));
      String thumb = cursor.getString(cursor.getColumnIndex("thumb"));
      String name = cursor.getString(cursor.getColumnIndex("name"));
      String content = cursor.getString(cursor.getColumnIndex("content"));
      String low_loc = cursor.getString(cursor.getColumnIndex("low_loc"));
      String high_loc = cursor.getString(cursor.getColumnIndex("high_loc"));
      String low_url = cursor.getString(cursor.getColumnIndex("low_url"));
      String pic_url = cursor.getString(cursor.getColumnIndex("pic_url"));
      User user = new User(name, thumb);
      PerItem perItem = new PerItem(content, pic_url, user, low_url, high_loc, format, low_loc);
      datas.add(perItem);
      JLog.e(format);
      JLog.e(thumb);
      JLog.e(name);
    }
    cursor.close();
    db.close();
    adapter = new ItemAdapter(this);
    rvCollect.setAdapter(adapter);
    adapter.addAll(datas);
  }
}
